package com.qf.rbac2202.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.qf.rbac2202.annotation.DataFilter;
import com.qf.rbac2202.sys.entity.SysDept;
import com.qf.rbac2202.sys.mapper.SysDeptMapper;
import com.qf.rbac2202.sys.service.ISysDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.rbac2202.utils.Constants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 部门管理 服务实现类
 * </p>
 *
 * @author dong_
 * @since 2022-10-28
 */
@Service
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService {

    @Transactional(propagation = Propagation.SUPPORTS)
    @DataFilter(dataField = "dept_id")
    @Override
    public List<SysDept> queryDeptByMap(Map<String, String> params) {

        final String sql = params.get(Constants.DATA_FILETER);

        final QueryWrapper<SysDept> sysDeptQueryWrapper = new QueryWrapper<>();
        sysDeptQueryWrapper.apply(StringUtils.isNotBlank(sql),sql);

        return this.list(sysDeptQueryWrapper);
    }
}
